home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / pyshared / pyme / callbacks.py < prev    next >
Encoding:
Python Source  |  2006-04-12  |  1.8 KB  |  48 lines

  1. # $Id: callbacks.py,v 1.6 2006/04/12 22:20:38 belyi Exp $
  2. # Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
  3. # Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
  4. #
  5. #    This library is free software; you can redistribute it and/or
  6. #    modify it under the terms of the GNU Lesser General Public
  7. #    License as published by the Free Software Foundation; either
  8. #    version 2.1 of the License, or (at your option) any later version.
  9. #
  10. #    This library is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. #    Lesser General Public License for more details.
  14. #
  15. #    You should have received a copy of the GNU Lesser General Public
  16. #    License along with this library; if not, write to the Free Software
  17. #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  18.  
  19. from getpass import getpass
  20.  
  21. def passphrase_stdin(hint, desc, prev_bad, hook=None):
  22.     """This is a sample callback that will read a passphrase from
  23.     the terminal.  The hook here, if present, will be used to describe
  24.     why the passphrase is needed."""
  25.     why = ''
  26.     if hook != None:
  27.         why = ' ' + hook
  28.     if prev_bad:
  29.         why += ' (again)'
  30.     print "Please supply %s' password%s:" % (hint, why)
  31.     return getpass()
  32.  
  33. def progress_stdout(what, type, current, total, hook=None):
  34.     print "PROGRESS UPDATE: what = %s, type = %d, current = %d, total = %d" %\
  35.           (what, type, current, total)
  36.     
  37. def readcb_fh(count, hook):
  38.     """A callback for data.  hook should be a Python file-like object."""
  39.     if count:
  40.         # Should return '' on EOF
  41.         return hook.read(count)
  42.     else:
  43.         # Wants to rewind.
  44.         if not hasattr(hook, 'seek'):
  45.             return None
  46.         hook.seek(0, 0)
  47.         return None
  48.